<?php 
/*
 module:		发布管理
 create_time:	2022-04-07 19:34:18
 author:		
 contact:		
*/

namespace app\backend\service;
use app\backend\model\ZhAuthentication;
use app\backend\model\ZhMatchmaker;
use think\exception\ValidateException;
use xhadmin\CommonService;

class ZhAuthenticationService extends CommonService {


	/*
 	* @Description  列表数据
 	*/
	public static function indexList($where,$field,$order,$limit,$page){
		try{
            $res = ZhAuthentication::alias('a')->leftJoin('zh_matchmaker m','a.matchmaker_id=m.matchmaker_id')->where($where)->field($field)->order($order)->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
        }catch(\Exception $e){
			abort(config('my.error_log_code'),$e->getMessage());
		}
		return ['rows'=>$res['data'],'total'=>$res['total']];
	}
    
    
    /*
     * @Description  修改
     */
    public static function update($data){
        
        try{
            validate(\app\backend\validate\ZhAuthentication::class)->scene('update')->check($data);
            
            $data['wxapp_id'] = session('backend.wxapp_id');
            $data['createtime'] = strtotime($data['createtime']);
            $res = ZhAuthentication::update($data);
        }catch(ValidateException $e){
            throw new ValidateException ($e->getError());
        }catch(\Exception $e){
            abort(config('my.error_log_code'),$e->getMessage());
        }
        if(!$res){
            throw new ValidateException ('操作失败');
        }
        return $res;
    }

    /*
     * @Description  添加
     */
    public static function add($data){

        try{

            $data['wxapp_id'] = session('backend.wxapp_id');
            $data['createtime'] = strtotime($data['createtime']);
            $res = ZhAuthentication::insert($data);
        }catch(ValidateException $e){
            throw new ValidateException ($e->getError());
        }catch(\Exception $e){
            abort(config('my.error_log_code'),$e->getMessage());
        }
        if(!$res){
            throw new ValidateException ('操作失败');
        }
        return $res;
    }


}

